package com.wondedDream.controller.admin;

import com.wondedDream.model.CourseCategory;
import com.wondedDream.service.CourseCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController(value = "adminCourseCategoryController")
@RequestMapping("/api/courseCategories")
@Api(description = "管理端-课程分类信息")
public class CourseCategoryController {

    @Autowired
    private CourseCategoryService courseCategoryService;

    // 创建新的课程分类
    @PostMapping("/")
    @ApiOperation(value = "创建新的课程分类")
    public CourseCategory createCourseCategory(@RequestBody CourseCategory category) {
        return courseCategoryService.saveCourseCategory(category);
    }


    // 根据课程id删除课程分类信息
    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据课程id删除课程分类信息")
    public void deleteCourseCategory(@PathVariable Integer id) {
        courseCategoryService.deleteCourseCategory(id);
    }


    // 根据课程id修改课程分类信息
    @PutMapping("/{id}")
    @ApiOperation(value = "根据课程id修改课程分类信息")
    public CourseCategory updateCourseCategory(@PathVariable Integer id, @RequestBody CourseCategory category) {
        category.setId(id);
        return courseCategoryService.updateCourseCategory(category);
    }

    // 根据id获取课程分类信息
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id获取课程分类信息")
    public CourseCategory getCourseCategoryById(@PathVariable Integer id) {
        return courseCategoryService.getCourseCategoryById(id);
    }

    // 获取所有课程分类信息
    @GetMapping("/")
    @ApiOperation(value = "获取所有课程分类信息")
    public List<CourseCategory> getAllCourseCategories() {
        return courseCategoryService.getAllCourseCategories();
    }
}